﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

using ServiceLayer.Entity;
using BusinessLogicLayer;
using DataAccessLayer;
using StockAdjust;
using Stationery_Store_Inventory_Management;

namespace ServiceLayer
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service.svc or Service.svc.cs at the Solution Explorer and start debugging.
    public class Service : IService
    {
        //static string connection = @"Data Source=(local);Initial Catalog=StationeryInventory;Integrated Security=True";
        //static string connection = @"Data Source=10.10.2.212;Initial Catalog=StationeryInventory;Persist Security Info=True;User ID=sa;Password=sa37team5!;MultipleActiveResultSets=True;Application Name=EntityFramework";

        StationeryInventoryEntities1 ent = new StationeryInventoryEntities1();

        LoginToSystemControl lt = new LoginToSystemControl();

        MakeRequistionController mr = new MakeRequistionController();

        ApproveRequisitionController ar = new ApproveRequisitionController();

        StoreRetrievalController sr = new StoreRetrievalController();

        DisbursementListController dl = new DisbursementListController();

        DisbursementHistoryControl dh = new DisbursementHistoryControl();

        IssueStockAdjustmentVoucherControl av = new IssueStockAdjustmentVoucherControl();


        #region login authentication
        //login authentication
        public bool Login(UserW user)
        {
            //List<string> list = lt.ValidateUserByUsernameAndPassword(user.UserID + "", user.Password);

            //string result = list[0];

            //if (result.Equals("validuser"))
            //    return true;

            //else return false;

            try
            {
                User u = ent.Users.FirstOrDefault(x => x.UserName == user.UserName);

                if (user.Password.Equals(u.Password)) return true;
                else return false;
            }
            catch (Exception ex){ }

            return false;

        }
        #endregion

        #region welcome
        //welcome get employee name by username
        public String GetEmpName(string userName)
        {
            Employee e = ent.Employees.FirstOrDefault(x => x.User.UserName == userName);
            return e.EmployeeName;
        }

        //welcome get department name by username
        public String GetDept(string userName)
        {
            User u = ent.Users.FirstOrDefault(x => x.UserName == userName);
            Employee e = ent.Employees.FirstOrDefault(x => x.UserID == u.UserID);
            Department d = ent.Departments.FirstOrDefault(x => x.DeptID == e.DeptID);

            return d.DeptName;
        }

        //welcome get role from username
        public RoleW GetRole(string userName)
        {
            User u = ent.Users.FirstOrDefault(x => x.UserName == userName);
            Role r = ent.Roles.FirstOrDefault(x => x.RoleID == u.RoleID);
            return RoleW.convert(r);
        }
        #endregion

        #region make requisition
        //make requisition get all category
        public CategoryW[] CategoryN()
        {
            var clist = (from c in ent.Categories
                         select c);
            return CategoryW.convertList(clist.ToList<Category>()).ToArray<CategoryW>();
        }


        //make requisition get all item based on choosed categoryName
        public StationeryW[] ItemN(string categoryName)
        {
            var list = (from s in ent.Stationeries
                        where s.Category.CategoryName == categoryName
                        select s);
            return StationeryW.convertList(list.ToList<Stationery>()).ToArray<StationeryW>();
        }

        //make requisition Submit
        public bool ReqSubmit(string userName, Req[] reqList)
        {
            try
            {
                int reqBy = mr.getEmpIDFromUserName(userName);
                int reqID = mr.makeRequisition(reqBy);

                for (int i = 0; i < reqList.Length; i++)
                {
                    string n = reqList[i].ItemName;
                    Stationery s = ent.Stationeries.FirstOrDefault(x => x.ItemName == n);
                    string itemCode = s.ItemCode;
                    int reqQty = reqList[i].Quantity;
                    mr.makeRequistionDetail(reqID, itemCode, reqQty);
                }
                mr.SendNotificationToDeptHead(userName, reqID);
                return true;
            }
            catch (Exception ex) { }
            return false;
        }
        #endregion

        #region approve requisition
        //approve requisition  get requisition employee name list
        public EmployeeW[] getRNList(string userName)
        {
            return EmployeeW.convertList(ar.getPendingEmpList(userName)).ToArray<EmployeeW>();
        }

        //approve requisition get approval list
        public App[] getAList(string empName)
        {
            Employee em = ent.Employees.FirstOrDefault(x => x.EmployeeName == empName);
            var reqList = (from x in ent.Requisitions where x.RequestedBy == em.EmployeeID && x.ApprovalStatus == "Pending" select x);
            List<Requisition> list = reqList.ToList<Requisition>();

            List<App> appList = new List<App>();
            foreach (Requisition x in list)
            {
                App a = new App();
                a.ReqID = x.ReqID;
                a.ReqDate = x.ReqDate.GetValueOrDefault().ToString();

                int id = x.RequestedBy.GetValueOrDefault();
                Employee e = ent.Employees.FirstOrDefault(y => y.EmployeeID == id);
                a.Name = e.EmployeeName;

                appList.Add(a);
            }

            return appList.ToArray<App>();

        }

        //approve requisition get all approval list
        public App[] getAllAList(string userName)
        {
            Employee e = ent.Employees.FirstOrDefault(x => x.User.UserName == userName);
            List<Employee> EmpList = (from x in ent.Employees where x.DeptID == e.DeptID select x).ToList();
            List<Requisition> allReqList = new List<Requisition>();

            for (int i = 0; i < EmpList.Count; i++)
            {
                int empId = EmpList[i].EmployeeID;
                var reqList = (from x in ent.Requisitions where x.RequestedBy == empId && x.ApprovalStatus == "Pending" select x);
                List<Requisition> reqLst = new List<Requisition>();
                reqLst = reqList.ToList<Requisition>();

                for (int j = 0; j < reqLst.Count; j++)
                {
                    allReqList.Add(reqLst[j]);
                }
            }

            List<App> appList = new List<App>();
            foreach (Requisition x in allReqList)
            {
                App a = new App();
                a.ReqID = x.ReqID;
                a.ReqDate = x.ReqDate.GetValueOrDefault().ToString();

                int id = x.RequestedBy.GetValueOrDefault();
                Employee ee = ent.Employees.FirstOrDefault(y => y.EmployeeID == id);
                a.Name = ee.EmployeeName;

                appList.Add(a);
            }

            return appList.ToArray<App>();

        }

        //approve requisition get requisition approval list details
        public AppDetail[] getRDList(string reqID)
        {
            int r = int.Parse(reqID);
            var reqDetList = (from x in ent.RequisitionDetailOnes where x.ReqID == r select x);
            List<RequisitionDetailOne> reqDetLst = reqDetList.ToList<RequisitionDetailOne>();

            List<AppDetail> appList = new List<AppDetail>();

            foreach (RequisitionDetailOne x in reqDetLst)
            {
                AppDetail a = new AppDetail();
                a.ReqID = x.ReqID.GetValueOrDefault();
                a.ItemName = x.Stationery.ItemName;
                a.RequestQty = x.RequestQty.GetValueOrDefault();
                a.Reason = x.Reason;
                a.ApprovalStatus = x.ApprovalStatus;
                appList.Add(a);
            }

            return appList.ToArray<AppDetail>();
        }

        //approve requisition submit approval result
        public bool AppSubmit(string reqName, string reqID, AppDetail[] appList)
        {
            try
            {
                string deptID = ent.Employees.FirstOrDefault(x => x.EmployeeName == reqName).DeptID;

                List<string> rdoStatus = new List<string>();
                List<string> reasons = new List<string>();

                foreach (AppDetail x in appList)
                {
                    rdoStatus.Add(x.ApprovalStatus);
                    reasons.Add(x.Reason);
                }

                ar.saveToDeptReq(deptID, int.Parse(reqID), rdoStatus, reasons);
                ar.SendNotificationToEmployee(ent.Employees.FirstOrDefault(x => x.EmployeeName == reqName).EmployeeID, deptID);

                return true;
            }
            catch (Exception ex) { }
            return false;
        }
        #endregion

        #region store retrieval
        //store retrieval get retrieval list and allocate it first
        public Ret[] getRetAndAlc()
        {
            //auto allocate first 
            sr.AutoAllocateActualQtyCont();


            //return retrieval list  -- make some changes to the controller code here
            var result = (from dr in ent.DeptRequisitions
                          join drd in ent.DeptRequisitionDetails on dr.DeptReqID equals drd.DeptReqID
                          join s in ent.Stationeries on drd.ItemCode equals s.ItemCode
                          where dr.RetrievedDate == null
                          group drd by new { drd.ItemCode, s.BinNo, s.ItemName, s.AvailableQty } into g
                          select new Ret
                          {
                              ItemCode = g.Key.ItemCode,
                              ItemName = g.Key.ItemName,
                              BinNo = g.Key.BinNo,
                              AvailableQty = g.Key.AvailableQty,
                              TotalQty = g.Sum(drd => drd.NewRequestQty).Value
                              //ActualQty = (System.Int32?)g.Sum(drd => drd.ActualQty)

                          }).ToList();

            return result.ToArray<Ret>();

        }

        //store retrieval confirm collection
        public bool confirmCon(string userName)
        {
            Employee emp = ent.Employees.FirstOrDefault(x => x.User.UserName == userName);
            int empID = emp.EmployeeID;

            try
            {
                sr.ConfirmWarehouseCollectionCont("" + empID);
                return true;
            }
            catch (Exception e) { }
            return false;

        }

        //store retrieval get retrieval allocation details based on item
        public RetDetail[] getRetDetail(string itemCode)
        {
            //make some changes to the controller code here
            var query = (from dr in ent.DeptRequisitions
                         join drd in ent.DeptRequisitionDetails on dr.DeptReqID equals drd.DeptReqID
                         join s in ent.Stationeries on drd.ItemCode equals s.ItemCode
                         join d in ent.Departments on dr.DeptID equals d.DeptID
                         where drd.ItemCode == itemCode && dr.RetrievedDate == null
                         select new RetDetail
                         {
                             DeptReqDetailID = drd.DeptReqDetailID,
                             DeptName = d.DeptName,
                             NewRequestQty = drd.NewRequestQty.Value,
                             ActualQty = drd.ActualQty.Value
                         }).ToList();
            return query.ToArray<RetDetail>();

        }

        //stroe retrieval allocate actuall quantity for each department
        public bool allocateQty(string itemCode, RetDetail[] retList)
        {
            try
            {
                List<int> lstDeptReqDetId = new List<int>();
                List<int> lstAllocatedQty = new List<int>();

                for (int i = 0; i < retList.Count(); i++)
                {
                    lstDeptReqDetId.Add(retList[i].DeptReqDetailID);
                    lstAllocatedQty.Add(retList[i].ActualQty);

                }

                sr.updateDeptReqDetActualQtyCont(lstDeptReqDetId, lstAllocatedQty);

                return true;
            }
            catch (Exception ex) { }

            return false;
        }
        #endregion

        #region store disbursment list
        //store disbursment list get all collection point name list
        public CollectionPointW[] getColPointNameList()
        {
            var list = (from c in ent.CollectionPoints
                        select c);
            return CollectionPointW.convertList(list.ToList<CollectionPoint>()).ToArray<CollectionPointW>();
        }

        //store disbursment list get department list for disbursement confirmation
        public Disburse[] getDeptListForDisburse(string colPoint)
        {
            int colPointId = ent.CollectionPoints.FirstOrDefault(x => x.CollectionPointName == colPoint).CollectionPointID;

            //make some changes to the controller code here
            List<string> deptNList = (from d in ent.Departments
                                      join c in ent.CollectionPoints on d.CollectionPointID equals c.CollectionPointID
                                      join dr in ent.DeptRequisitions on d.DeptID equals dr.DeptID
                                      where dr.DisbursedBy == null && dr.RetrievedDate != null && d.CollectionPointID == colPointId
                                      select d.DeptName).ToList<string>();



            //make some changes to the controller code here
            List<Disburse> disList = new List<Disburse>();

            foreach (string deptName in deptNList)
            {
                Disburse dis = new Disburse();

                dis.CollectionPointName = colPoint;
                dis.DeptName = deptName;
                dis.CollectionDate = dl.getCollectionDateCont(deptName).ToShortDateString();
                dis.CollectionTime = dl.getColPointTimeCont(colPoint).ToShortTimeString();
                dis.EmployeeName = dl.getRepNameCont(deptName);
               
                dis.Status = ""; //in this use case this field is unused
                dis.CollectionPointDetailID = 1; //in this use case this field is unused

                disList.Add(dis);
            }

            return disList.ToArray<Disburse>();

        }

        //store disbursment list get item list for disbursment of selected department
        public DisDetail[] getDisburseItemList(string deptName)
        {
            Department department = ent.Departments.FirstOrDefault(x => x.DeptName == deptName);

            //make some changes to the controller code here
            DeptRequisition dr = (from d1 in ent.DeptRequisitions
                                  where d1.DeptID == department.DeptID
                                  orderby d1.RetrievedDate descending
                                  select d1).FirstOrDefault();

            var ItemsAndQty = (from dd in ent.DeptRequisitionDetails
                               where dd.DeptReqID == dr.DeptReqID
                               select new DisDetail
                               {
                                   ItemName = dd.Stationery.ItemName,
                                   OriginalQty = dd.ActualQty.Value,
                                   ActualQty = dd.ActualQty.Value,
                                   DeptReqDetailID = dd.DeptReqDetailID

                               }).ToList<DisDetail>();

            return ItemsAndQty.ToArray<DisDetail>();


        }

        //store disbursment list update lost/damaged qty and confirm disbursement list by clerk
        public bool confirmByClerk(string userName, string deptName, DisDetail[] list)
        {
            try
            {
                //update lost/damaged item qty
                for (int i = 0; i < list.Count(); i++)
                {
                    int oriQty = list[i].OriginalQty;
                    int actQty = list[i].ActualQty;

                    if (actQty < oriQty)
                    {
                        string iName = list[i].ItemName;
                        int deptReqDetId = list[i].DeptReqDetailID;

                        List<int> lstDeptReqDetId = new List<int>();
                        lstDeptReqDetId.Add(deptReqDetId);
                        List<int> lstAllocatedQty = new List<int>();
                        lstAllocatedQty.Add(actQty);

                        dl.UpdateDeptReqDetAndAdjAndStockHistory(oriQty - actQty, iName, lstDeptReqDetId, lstAllocatedQty);   

                    }

                }

                Department department = ent.Departments.FirstOrDefault(x => x.DeptName == deptName);
                Employee employee = ent.Employees.FirstOrDefault(x => x.User.UserName == userName);

                //confirm disbursement list
                dl.updDisbursementDetailsCont(department.DeptID, employee.EmployeeID + "");    

                return true;
            }
            catch (Exception e){}
            return false;

        }

        #endregion

        #region Department disbursment list
        //Department disbursment list get department list for viewing disbursement history
        public Disburse[] getDisburseHistory(string userName)
        {
            User u = ent.Users.FirstOrDefault(x => x.UserName == userName);
            Employee e = ent.Employees.FirstOrDefault(x => x.UserID == u.UserID);
            Department d = ent.Departments.FirstOrDefault(x => x.DeptID == e.DeptID);

            Employee currentRep = ent.Employees.FirstOrDefault(x => x.EmployeeID == d.RepresentativeID);


            int roleID = u.RoleID;
            List<Disburse> list = new List<Disburse>();

            if (roleID == 2) //2 stands for representative
            {
                //Confirmed By Store Clerk
                List<DeptRequisition> toBeConfirmedList = new List<DeptRequisition>();

                toBeConfirmedList = (from dr in ent.DeptRequisitions
                                     where dr.DeptID == d.DeptID && dr.DisbursedBy != null && dr.CollectedBy == null
                                     select dr).ToList<DeptRequisition>();

                foreach (DeptRequisition x in toBeConfirmedList)
                {
                    Disburse dis = new Disburse();
                    CollectionPointDetail c = ent.CollectionPointDetails.FirstOrDefault(y => y.CollectionPointDetailID == x.CollectionPointDetailID);

                    dis.CollectionPointName = c.CollectionPoint.CollectionPointName;
                    dis.CollectionDate = c.CollectionDate.ToShortDateString();
                    dis.CollectionTime = c.CollectionTime.ToShortTimeString();
                    dis.DeptName = d.DeptName;
                    dis.EmployeeName = currentRep.EmployeeName;
                    dis.Status = "Confirmed By Clerk";
                    dis.CollectionPointDetailID = c.CollectionPointDetailID;

                    list.Add(dis);
                }

                //Pending
                List<DeptRequisition> pendList = new List<DeptRequisition>();

                pendList = (from dr in ent.DeptRequisitions
                            where dr.DeptID == d.DeptID && dr.CollectionPointDetailID != null && dr.DisbursedBy == null
                            select dr).ToList<DeptRequisition>();


                foreach (DeptRequisition x in pendList)
                {
                    Disburse dis = new Disburse();
                    CollectionPointDetail c = ent.CollectionPointDetails.FirstOrDefault(y => y.CollectionPointDetailID == x.CollectionPointDetailID);

                    dis.CollectionPointName = c.CollectionPoint.CollectionPointName;
                    dis.CollectionDate = c.CollectionDate.ToShortDateString();
                    dis.CollectionTime = c.CollectionTime.ToShortTimeString();
                    dis.DeptName = d.DeptName;
                    dis.EmployeeName = currentRep.EmployeeName;
                    dis.Status = "Pending";
                    dis.CollectionPointDetailID = c.CollectionPointDetailID;

                    list.Add(dis);

                }

                //Collected
                List<DeptRequisition> collectedList = new List<DeptRequisition>();

                collectedList = (from dr in ent.DeptRequisitions
                                 where dr.DeptID == d.DeptID && dr.CollectedBy != null
                                 select dr).ToList<DeptRequisition>();

                foreach (DeptRequisition x in collectedList)
                {
                    Disburse dis = new Disburse();
                    CollectionPointDetail c = ent.CollectionPointDetails.FirstOrDefault(y => y.CollectionPointDetailID == x.CollectionPointDetailID);

                    dis.CollectionPointName = c.CollectionPoint.CollectionPointName;
                    dis.CollectionDate = c.CollectionDate.ToShortDateString();
                    dis.CollectionTime = c.CollectionTime.ToShortTimeString();
                    dis.DeptName = d.DeptName;

                    Employee previousRep = ent.Employees.FirstOrDefault(y => y.EmployeeID == x.CollectedBy);
                    dis.EmployeeName = previousRep.EmployeeName;
                    dis.Status = "Collected";
                    dis.CollectionPointDetailID = c.CollectionPointDetailID;

                    list.Add(dis);
                }


            }

            else //stands for ordinary employee and dept head or acting manager
            {
                //Pending
                List<DeptRequisition> pendList = new List<DeptRequisition>();

                pendList = (from dr in ent.DeptRequisitions
                            where dr.DeptID == d.DeptID && dr.RetrievedBy != null && dr.CollectedBy == null
                            select dr).ToList<DeptRequisition>();

                foreach (DeptRequisition x in pendList)
                {
                    Disburse dis = new Disburse();
                    CollectionPointDetail c = ent.CollectionPointDetails.FirstOrDefault(y => y.CollectionPointDetailID == x.CollectionPointDetailID);

                    dis.CollectionPointName = c.CollectionPoint.CollectionPointName;
                    dis.CollectionDate = c.CollectionDate.ToShortDateString();
                    dis.CollectionTime = c.CollectionTime.ToShortTimeString();
                    dis.DeptName = d.DeptName;
                    dis.EmployeeName = currentRep.EmployeeName;
                    dis.Status = "Pending";
                    dis.CollectionPointDetailID = c.CollectionPointDetailID;

                    list.Add(dis);

                }

                //Collected
                List<DeptRequisition> collectedList = new List<DeptRequisition>();

                collectedList = (from dr in ent.DeptRequisitions
                                 where dr.DeptID == d.DeptID && dr.CollectedBy != null
                                 select dr).ToList<DeptRequisition>();

                foreach (DeptRequisition x in collectedList)
                {
                    Disburse dis = new Disburse();
                    CollectionPointDetail c = ent.CollectionPointDetails.FirstOrDefault(y => y.CollectionPointDetailID == x.CollectionPointDetailID);

                    dis.CollectionPointName = c.CollectionPoint.CollectionPointName;
                    dis.CollectionDate = c.CollectionDate.ToShortDateString();
                    dis.CollectionTime = c.CollectionTime.ToShortTimeString();
                    dis.DeptName = d.DeptName;

                    Employee previousRep = ent.Employees.FirstOrDefault(y => y.EmployeeID == x.CollectedBy);
                    dis.EmployeeName = previousRep.EmployeeName;
                    dis.Status = "Collected";
                    dis.CollectionPointDetailID = c.CollectionPointDetailID;

                    list.Add(dis);
                }


            }

            return list.ToArray<Disburse>();
        }

        //Department disbursment list get item list for each disbursment of selected department
        public DisDetail[] getDisburseHistoryItemList(string userName, string colDetId, string day, string month, string year)
        {
            string colDate = "" + day + "/" + month + "/" + year;

            DateTime collectionDate = DateTime.Parse(colDate);

            //call controller
            int deptReqID = dh.getDeptReqID(userName, collectionDate, colDetId);


            //make some changes to the controller code here
            List<DisDetail> deptReqDetail = (from drd in ent.DeptRequisitionDetails
                                             where drd.DeptReqID == deptReqID
                                             select new DisDetail
                                             {
                                                 ItemName = drd.Stationery.ItemName,
                                                 OriginalQty = drd.ActualQty.Value, // in this use case this field is not needed
                                                 ActualQty = drd.ActualQty.Value,
                                                 DeptReqDetailID = drd.DeptReqDetailID // in this use case this field is not needed

                                             }).ToList<DisDetail>();

            return deptReqDetail.ToArray<DisDetail>();
        }

        //Department disbursment list confirm disbursement list by dept representative
        public bool confirmByRepresentative(string userName, string colDetId, string day, string month, string year)
        {
            try
            {
                string colDate = "" + day + "/" + month + "/" + year;

                DateTime collectionDate = DateTime.Parse(colDate); 

                //call controller
                int deptReqID = dh.getDeptReqID(userName, collectionDate, colDetId);


                //make some changes to the controller code here
                Employee currentRep = ent.Employees.FirstOrDefault(x => x.User.UserName == userName); // or just retrieve from the department table

                DeptRequisition currentDeptReq = ent.DeptRequisitions.FirstOrDefault(x => x.DeptReqID == deptReqID);
                currentDeptReq.CollectedBy = currentRep.EmployeeID;

                ent.SaveChanges();

                return true;
            }
            catch (Exception ex){}

            return false;

        }
        #endregion

        #region issue ajustment voucher

        //issue ajustment voucher display all category name
        public CategoryW[] getCateNameList()
        {
            return CategoryW.convertList(av.DisplayAllCategory()).ToArray<CategoryW>();
        }

        //issue ajustment voucher display all item name by chosed category
        public StationeryW[] getItemNameList(string cateName)
        {
            int cateId = ent.Categories.FirstOrDefault(x => x.CategoryName == cateName).CategoryID;

            return StationeryW.convertList(av.DisplayStationeryByCategoryId(cateId)).ToArray<StationeryW>();
        }

        //issue ajustment voucher display all supplier name by chosed item
        public SupplierW[] getSupNameList(DisDetail item)
        {
            string itemName = item.ItemName;

            string itemCode = ent.Stationeries.FirstOrDefault(x => x.ItemName == itemName).ItemCode;

            return SupplierW.convertList(av.DisplaySupplierByItemCode(itemCode)).ToArray<SupplierW>();
        }

        //issue ajustment voucher submit adjustment voucher
        public bool adjSubmit(string userName, StockAdj[] adjList)
        {
            User user = av.GetUserByUsername(userName);

            List<StockAdjustment> list = new List<StockAdjustment>();

            foreach (StockAdj x in adjList)
            {
                StockAdjustment s = new StockAdjustment();

                s.UserId = user.UserID;

                s.ItemCode = ent.Stationeries.FirstOrDefault(y => y.ItemName == x.ItemName).ItemCode;
                s.ItemName = x.ItemName;

                s.CategoryId = ent.Categories.FirstOrDefault(y => y.CategoryName == x.CategoryName).CategoryID;
                s.CategoryName = x.CategoryName;

                s.SupplierId = ent.Suppliers.FirstOrDefault(y => y.SupplierName == x.SupplierName).SupplierID;
                s.SupplierName = x.SupplierName;

                s.AdjustQuantity = x.AdjustQuantity;
                s.AdjustCondition = x.AdjustCondition;
                s.Reason = x.Reason;

                list.Add(s);

            }

            av.SaveAdjustmentVoucher(user, list);

            return true;

        }

        //issue ajustment voucher get available quantity based on item name
        public DisDetail getCurrentQty(DisDetail item)
        {
            Stationery stationery = ent.Stationeries.FirstOrDefault(x => x.ItemName == item.ItemName);

            DisDetail d = new DisDetail();
            d.ItemName = "dummy";
            d.OriginalQty = stationery.AvailableQty;
            d.ActualQty = 1;
            d.DeptReqDetailID = 1;

            return d;
        }

        #endregion

        #region Test
        //Test
        public UserW[] List()
        {
            var ulist = (from u in ent.Users select u);

            return (UserW.convertList(ulist.ToList<User>())).ToArray<UserW>();
        }
        //Test
        public String Call()
        {
            //Department r = ent.Departments.FirstOrDefault(x =>x.DeptID == "COMM");
            //return r.ActingManagerID.GetValueOrDefault().ToString();
            //return (new DateTime()).ToString();

            Stationery s = ent.Stationeries.FirstOrDefault(x => x.ItemName == "Clips 3/4\"");
            string itemCode = s.ItemCode;
            return itemCode;

        }
        //Test
        public bool LC(UserW[] list)
        {
            if (list[0].UserID == list[1].UserID)
            {
                return true;
            }
            return false;
        }

        //Test
        public bool dou(string a, string b)
        {
            if (a.Equals(b)) return true;
            else return false;
        }

        #endregion

    }
}
